<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>

</head>
<body class="hold-transition">
<div id="app">
    <div class="add-form">

        <template>
            <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
                <el-tab-pane label="添加地图" name="first">
                    <iframe src="map.html" height="500px" width="100%"></iframe>
                </el-tab-pane>
                    <el-tab-pane label="地址列表" name="second" >
                        <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                            <el-table-column type="index" label="序号" align="center"></el-table-column>
                            <el-table-column prop="addressName" label="地址名称" align="center"></el-table-column>
                            <el-table-column prop="point" label="地址经纬坐标" align="center"></el-table-column>
                            <el-table-column label="操作" align="center">
                                <template slot-scope="scope">
                                    <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-tab-pane>
            </el-tabs>
        </template>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',//Tab标签名称
            dataList: [],
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            }
        },
        created() {
            //调用分页查询方法完成分页查询
            this.findPage();
        },
        methods: {
            handleClick() {
                this.findPage();
            },
            findthis() {
                this.findPage();
            },
            //分页查询
            findPage() {
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };

                //发送ajax请求，进行分页查询
                axios.post("/address/findPage.do", param).then((res) => {
                    this.pagination.total = res.data.total;
                    this.dataList = res.data.rows;
                });

            },

            // 删除
            handleDelete(row) {
                //弹出确认框
                this.$confirm('你确定要删除当前数据吗？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //发送ajax请求，将id提交到Controller
                    axios.get("/address/delete.do?id=" + row.id).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                type: 'success',
                                message: res.data.message
                            });
                            this.findPage();
                        } else {
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    });
                }).catch(() => {
                    this.$message("已取消");
                });
            }


        }
    })
</script>
</html>